package emqMQTT;

import org.fusesource.mqtt.client.*;

/**
 * Created with IDEA
 * author:Yhk
 * Date:2019/6/29
 * Time:9:15 PM
 */
public class jieshou {
    private static int flag = 0;

    public static void main(String[] args) throws Exception {
        MQTT mqtt = new MQTT();
        mqtt.setHost("tcp://47.98.204.175:1883");
        BlockingConnection connection = mqtt.blockingConnection();
        connection.connect();
        Topic[] topics = {new Topic("foo", QoS.AT_LEAST_ONCE)};
        byte[] qoses = connection.subscribe(topics);
        Message message = connection.receive();
        System.out.println(message.getPayloadBuffer().getData().toString());
        System.out.println(message.getTopic() + "-----" + message.getPayloadBuffer().toString());
//        connection.disconnect();
    }
}
